package com.union.utils;

import android.os.CountDownTimer;
import android.os.Handler;


/**
 * 发送验证码倒计时工具类
 * Created by Administrator on 2016/5/23.
 */
public class CountDownUtils {
    private static Handler handler;
    public static final int TIMECOUNTER = 1001;
    public static final int FINISH = 1002;
    public static int TOTALTIME =300000;
    private static CountDownTimer start;

    public static void setHandler(Handler handler) {
        CountDownUtils.handler = handler;
    }

    public static void startCouner(){
     start = new CountDownTimer(TOTALTIME, 1000) {

            public void onTick(long millisUntilFinished) {
                handler.sendMessage(handler.obtainMessage(TIMECOUNTER, millisUntilFinished));
            }

            public void onFinish() {
                handler.sendEmptyMessage(FINISH);
            }
        }.start();
    }

    public static  void stopCounter(){
        if(start!=null){
            start.cancel();
        }
    }
}
